
//
// 110410 - AH - Created.
// 110423 - AH - No more direct access to ontology on SoekratEngine, must
//               use getWheel() first to get.
// 110604 - AH - (Bybanen) Changes related to that tags are no longer String
//               but SoekratName objects.
//

package org.soekrat.engine.pitbul.generator;

import java.io.IOException;
import java.io.PrintWriter;

import org.soekrat.engine.Soekrat2Engine;
import org.soekrat.engine.SoekratName;
import org.soekrat.engine.mine.Mine;
import org.soekrat.engine.mine.Resource;
import org.soekrat.engine.mine.Tags;

/**
 * <p>
 *   {@link FormGenerator} that generates code for the resource form.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC)
 */
public final class ResourceFormGenerator extends FormGenerator 
{
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public ResourceFormGenerator(){ super("resource"); }

  @Override
  public void generate(Soekrat2Engine se, PrintWriter pw) throws IOException 
  {
    Mine mine=se.getWheel().getMine();
    for (Resource resource : mine) 
    {
      pw.print("{resource *be ");
      pw.print("'"+resource.getName()+"'");
     
      Tags tags=(Tags)resource.getAttribute("tags");
      boolean first=true;
      if (tags!=null)
      {
        for (SoekratName tag : tags)
        {
          if (first) pw.print(" #center");
          first=false;
          pw.print(" '"+tag+"'");  
        }
      }
      
      pw.println("}");
    }
    
  }
  
}
